<template>

        <div class="loginWaip">
            <el-dialog v-model="dialogVisible" width="30%" class="diagFlag" title="请绑定银行卡" center>
                <el-form ref="form" :model="form">

                    <el-form-item prop="cardId" label="银行卡号" :rules="[{ required: true, message: '请填写正确的银行卡号',trigger:'blur' }]">
                        <el-input
                                v-model="form.cardId"
                                autocomplete="off"
                                placeholder="请绑定银行卡号"
                        ></el-input>
                    </el-form-item>

                    <el-button @click.stop="bind">绑定</el-button>

                </el-form>

            </el-dialog>

        </div>

</template>

<script>
    import {AdaSettleAccountCreate} from "../../api/dsp/pay";
    import {UserInfoDetail} from "../../api/UserInfo";
    import {setUserInfo} from "../../utils/auth";

    export default {

        data(){
            return{
                dialogVisible:false,
                form:{},
            }
        },
        created(){
          console.log('在bindcard中',this.dialogVisible)
        },
        methods:{

            bind(){

                this.$refs['form'].validate(valid=>{
                    if(valid){
                        console.log('数据为：',this.form)
                        AdaSettleAccountCreate(this.form).then(res=>{
                            console.log('绑卡结果为：',res)
                            if(res.code == 1){
                                this.$message.error(res.data)
                                return
                            }

                            if(res.data.status == "succeeded"){
                                this.$message.success('绑卡成功');
                                UserInfoDetail().then(res1=>{
                                    setUserInfo(res1.data)
                                    this.$store.commit("setUser",res1.data)
                                })
                                setTimeout(()=>{
                                    window.location.reload()
                                },500)

                            }else{
                                this.$message.error('绑卡失败');
                            }

                        })

                    }else{

                        console.log("error submit!!");
                        return false;
                    }
                })
            },
        }
    }
</script>

<style scoped lang="scss">
    .loginWaip {
        overflow: hidden;
        ::v-deep{
            .el-button{
                display: block;
                margin: 0px auto;
                background: #2EB0C6;
                color: white;
            }
        }
    }

</style>
